/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.admin.model.base;

import com.admin.model.pojo.User;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.Null;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 通用字段， is_del 根据需求自行添加
 *
 * @author Zheng Jie
 * @Date 2019年10月24日20:46:32
 */

@Getter
@Setter
public class BaseDto implements Serializable {
    /**
     * 创建者
     */
    @ApiModelProperty("创建者")
    // @Null(message = "创建人必须为空", groups = {Create.class, Update.class})
    @JsonSerialize(using = ToStringSerializer.class)
    private Long createdBy;
    /**
     * 创建者
     */
    @ApiModelProperty("创建者")
    private User createdUser;
    /**
     * 更新者
     */
    @ApiModelProperty("更新者")
    // @Null(message = "更新者必须为空", groups = {Create.class, Update.class})
    @JsonSerialize(using = ToStringSerializer.class)
    private Long updatedBy;
    /**
     * 更新者
     */
    @ApiModelProperty("更新者")
    private User updatedUser;
    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    // @Null(message = "创建时间必须为空", groups = {Create.class, Update.class})
    //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @ApiModelProperty("更新时间")
    // @Null(message = "更新时间必须为空", groups = {Create.class, Update.class})
    //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;


    /* 分组校验 */
    public @interface Create {
    }

    /* 分组校验 */
    public @interface Update {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseDto baseDto = (BaseDto) o;
        return Objects.equals(createdBy, baseDto.createdBy) &&
                Objects.equals(updatedBy, baseDto.updatedBy) &&
                Objects.equals(createTime, baseDto.createTime) &&
                Objects.equals(updateTime, baseDto.updateTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(createdBy, updatedBy, createTime, updateTime);
    }
}
